﻿using ViewMaker.Core.Controls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using ViewMaker.Core;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows;

namespace ViewMaker.Core.Tests
{
    [TestClass()]
    public class TextBoxViewControlTest
    {
        [TestMethod()]
        public void 標準的なTextBoxのXAML生成()
        {
            var target = new TextBoxViewControl { Item = new ViewLayoutItem { Name = "txt001", Caption = "テキスト", BindPath = "textPath" } };
            var xaml = target.CreateXaml(TestHelper.CreateTestParent())[1];

            var actual = TestHelper.GetFrameworkElement<TextBox>(xaml);
            Assert.AreEqual("txt001", actual.Name);
            Assert.AreEqual("textPath", actual.GetBindingExpression(TextBox.TextProperty).ParentBinding.Path.Path);
            Assert.AreEqual(BindingMode.TwoWay, actual.GetBindingExpression(TextBox.TextProperty).ParentBinding.Mode);

        }

        [TestMethod()]
        public void 複数行TextBoxなXAML生成()
        {
            var target = new TextBoxViewControl { Item = new ViewLayoutItem { Name = "txt001", Caption = "テキスト", BindPath = "textPath" } };
            target.IsMultiline = true;
            var xaml = target.CreateXaml(TestHelper.CreateTestParent())[1];

            var actual = TestHelper.GetFrameworkElement<TextBox>(xaml);
            Assert.AreEqual("txt001", actual.Name);
            Assert.AreEqual("textPath", actual.GetBindingExpression(TextBox.TextProperty).ParentBinding.Path.Path);
            Assert.AreEqual(BindingMode.TwoWay, actual.GetBindingExpression(TextBox.TextProperty).ParentBinding.Mode);
            Assert.AreEqual(TextWrapping.Wrap, actual.TextWrapping);
            Assert.AreEqual(true, actual.AcceptsReturn);
            Assert.AreEqual(ScrollBarVisibility.Auto, actual.VerticalScrollBarVisibility);

        }

        [TestMethod()]
        public void 読み取り専用フォーマットTextBoxなXAML生成()
        {
            var target = new TextBoxViewControl { Item = new ViewLayoutItem { Name = "txt001", Caption = "ラベル", BindPath = "textPath", IsOneWay=true } };
            target.IsReadOnly = true;
            target.StringFormat = "yyyy/mm/dd";
            target.IsEmptyAsNull = true;
            var parent = TestHelper.CreateTestParent();
            parent.AppendChild(target.CreateXaml(parent)[1]);
            var xaml = parent;


            var actual = (TextBox)TestHelper.GetFrameworkElement<ContentControl>(xaml).Content;
            Assert.AreEqual("txt001", actual.Name);
            Assert.AreEqual("textPath", actual.GetBindingExpression(TextBox.TextProperty).ParentBinding.Path.Path);
            Assert.AreEqual(BindingMode.OneWay, actual.GetBindingExpression(TextBox.TextProperty).ParentBinding.Mode);
            Assert.AreEqual("yyyy/mm/dd", actual.GetBindingExpression(TextBox.TextProperty).ParentBinding.StringFormat);
            Assert.AreEqual("", actual.GetBindingExpression(TextBox.TextProperty).ParentBinding.TargetNullValue);

        }

        [TestMethod()]
        public void TextBoxViewControlの編集画面が表示可能()
        {
            var target = new TextBoxViewControl { Item = new ViewLayoutItem { Name = "txt001", Caption = "テキスト", BindPath = "textPath" } };
            var baml = ViewUtil.BuildContent(target);
            Assert.IsNotNull(baml);
        }

    }
}
